package com.model.rule;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.edu.hfut.dmic.webcollector.crawler.Crawler;

import com.vs.crawl.news.WriteCrawler;

import constant.XmlElementCoonstant;

/**
 * *********************************************
 * @author Administrator
 * @FileName WriteFileRuleBytes.java
 * @Description 写入规则(根据字节数写入)
 **********************************************
 */
public class WriteFileRuleBytes extends FileRule{
	public static final Logger LOG = LoggerFactory.getLogger(WriteFileRuleBytes.class);

	public WriteFileRuleBytes() {
		super();
	}

	@Override
	public void executeFileRule() {
		WriteCrawler writeCrawler = this.getWriteCrawler();
		Crawler crawler = writeCrawler.getCrawler();
		long kbs = 0L;
		String value = super.getValue();
		if(value == null || value.equals("")){
			kbs = XmlElementCoonstant.DEFAULT_CAPACITY;
		}else{
			kbs = Long.valueOf(value) * 1024;
			if(kbs <= 0){
				kbs = XmlElementCoonstant.DEFAULT_CAPACITY;
			}
		}
		LOG.info("WriteFileRuleBytes->totalBytesLength->" + crawler.getTotalBytesLength() + "----------kbs->" + kbs);
		
		if(crawler.getTotalBytesLength().get() > kbs){
			writeCrawler.writeData();
		}
	}

}
